home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-02 / pas_0593.zip / GETSTRNG.PAS < prev    next >
Pascal/Delphi Source File  |  1993-05-30  |  2KB  |  80 lines

  1. {─ Fido Pascal Conference ────────────────────────────────────────────── PASCAL ─
  2. Msg  : 319 of 410
  3. From : Nico Keirsmakers                    2:292/804.3          09 May 93  11:41
  4. To   : Steven O'neal                       1:3800/22.0
  5. Subj : Line Fields
  6. ────────────────────────────────────────────────────────────────────────────────
  7. Hello Steven!
  8.  
  9. 30 Apr 93, Steven O'neal writes to All:
  10.  
  11.  SO> :_________________________________________________________________________
  12.  SO> _ ___: / \
  13.  
  14.  SO> how can i make the users keyboard lock from typeing over the colon, or
  15.  SO> keep retyping the last char..  thanx for any help!!
  16.  
  17. Here's a routine I made some time ago to do this :}
  18.  
  19.  
  20. Function GetString(cx,cy : integer; Prompt : String; MaxLen : Integer;OKSet :
  21. charset):string;
  22.  
  23. const
  24.   BS                 = ^H;
  25.   CR                 = ^M;
  26.   ConSet             : CharSet = [BS,CR];
  27. var
  28.   TStr               : string;
  29.   TLen,X,i           : Integer;
  30.   Ch                 : Char;
  31. begin
  32.   {$I-} { turn off I/O checking }
  33.   TStr := '';
  34.   TLen := 0;
  35.   Print(cx,cy,Prompt);
  36.   X := cx + Length(Prompt);
  37.   For i := x to (x + Maxlen - 1) do
  38.     Print(i,cy,'_');
  39.   Print(x,cy,Default);
  40.   OKSet := OKSet + ConSet;
  41.   repeat
  42.     Gotoxy(x,cy);
  43.     repeat
  44.       ch := readkey
  45.     until Ch in OKSet;
  46.     if Ch = BS then begin
  47.       if TLen > 0 then begin
  48.         TLen := TLen - 1;
  49.         X := X - 1;
  50.         GoToXY(X,cy); Write('_');
  51.       end
  52.     end
  53.     else if (Ch <> CR) and (TLen < MaxLen) then begin
  54.       Write(Ch);
  55.       TLen := TLen + 1;
  56.       TStr[TLen] := Ch;
  57.       X := X + 1;
  58.     end
  59.   until Ch = CR;
  60.   If Tlen > 0
  61.     Then Begin
  62.            TStr[0] := chr(Tlen);
  63.            Getstring := TStr
  64.          End
  65.     Else Getstring := Default;
  66.   {$I+}
  67. end;
  68.  
  69.  
  70. Use it like this :
  71.  
  72.  
  73.    Default := 'BELGIUM';
  74.    Country := Getstring(16, 5,'Enter country : ',25,['a'..'z','A'..'Z',' ']);
  75.  
  76. Output is like this :
  77.  
  78.    Enter country : BELGIUM___________________
  79.                           ^\
  80.                             Cursor will be here.